Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Context-adaptive variable-length coding</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Context-adaptive_variable-length_coding"> <link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Context-adaptive_variable-length_coding rootpage-Context-adaptive_variable-length_coding skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Context-adaptive variable-length coding</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>
<p><b>Context-adaptive <a href="Variable-length_code" title="Variable-length code">variable-length coding</a></b> (<b>CAVLC</b>) is a form of <a href="Entropy_coding" title="Entropy coding">entropy coding</a> used in <a href="H.264/MPEG-4_AVC" class="mw-redirect" title="H.264/MPEG-4 AVC">H.264/MPEG-4 AVC</a> video encoding. It is an inherently <a href="Lossless_compression" title="Lossless compression">lossless compression</a> technique, like almost all entropy-coders. In H.264/MPEG-4 AVC, it is used to encode residual, zig-zag order, blocks of transform coefficients. It is an alternative to <a href="Context-adaptive_binary_arithmetic_coding" title="Context-adaptive binary arithmetic coding">context-adaptive binary arithmetic coding</a> (CABAC). CAVLC requires considerably less processing to decode than CABAC, although it does not compress the data quite as effectively. CAVLC is supported in all H.264 profiles, unlike CABAC which is not supported in Baseline and Extended profiles.
</p><p>CAVLC is used to encode residual, zig-zag ordered 4×4 (and 2×2) blocks of transform coefficients. CAVLC is designed to take advantage of several characteristics of quantized 4×4 blocks:
</p>
<ul><li>After prediction, transformation and quantization, blocks are typically sparse (containing mostly zeros).</li>
<li>The highest non-zero coefficients after zig-zag scan are often sequences of +/− 1. CAVLC signals the number of high-frequency +/−1 coefficients in a compact way.</li>
<li>The number of non-zero coefficients in neighbouring blocks is correlated. The number of coefficients is encoded using a look-up table; the choice of look-up table depends on the number of non-zero coefficients in neighbouring blocks.</li>
<li>The level (magnitude) of non-zero coefficients tends to be higher at the start of the reordered array (near the DC coefficient) and lower towards the higher frequencies. CAVLC takes advantage of this by adapting the choice of VLC look-up table for the "level" parameter depending on recently coded level magnitudes.</li></ul>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Coded_elements">Coded elements</h2></div>
<p>Parameters that required to be encoded and transmitted include the following table:
</p>
<table class="wikitable">

<tbody><tr>
<th>Parameters
</th>
<th>Description
</th></tr>
<tr>
<td>Macroblock type
</td>
<td>Prediction method for each coded macroblock
</td></tr>
<tr>
<td>Coded block pattern
</td>
<td>Indicates which blocks within a macroblock contain coded coefficients
</td></tr>
<tr>
<td>Quantizer parameter reference frame
</td>
<td>Transmitted as a delta value from the previous value of QP
</td></tr>
<tr>
<td>Reference frame index
</td>
<td>Identify reference frame(s) for inter prediction
</td></tr>
<tr>
<td>Motion vector
</td>
<td>Transmitted as a difference (mvd) from predicted motion vector
</td></tr>
<tr>
<td>Residual data
</td>
<td>Coefficient data for each 4×4 or 2×2 block
</td></tr></tbody></table>
<div class="mw-heading mw-heading2"><h2 id="CAVLC_examples">CAVLC examples</h2></div>
<table class="wikitable floatright">
<tbody><tr>
<th>Element
</th>
<th>Value
</th>
<th>Code
</th></tr>
<tr>
<td>coeff_token
</td>
<td>TotalCoeffs=5, T1s=3
</td>
<td>0000100
</td></tr>
<tr>
<td>T1 sign (4)
</td>
<td>+
</td>
<td>0
</td></tr>
<tr>
<td>T1 sign (3)
</td>
<td>-
</td>
<td>1
</td></tr>
<tr>
<td>T1 sign (2)
</td>
<td>-
</td>
<td>1
</td></tr>
<tr>
<td>Level (1)
</td>
<td>+1 (use Level_VLC0)
</td>
<td>1
</td></tr>
<tr>
<td>Level (0)
</td>
<td>+3 (use Level_VLC1)
</td>
<td>0010
</td></tr>
<tr>
<td>TotalZeros
</td>
<td>3
</td>
<td>111
</td></tr>
<tr>
<td>run_before(4)
</td>
<td>ZerosLeft=3; run_before=1
</td>
<td>10
</td></tr>
<tr>
<td>run_before(3)
</td>
<td>ZerosLeft=2; run_before=0
</td>
<td>1
</td></tr>
<tr>
<td>run_before(2)
</td>
<td>ZerosLeft=2; run_before=0
</td>
<td>1
</td></tr>
<tr>
<td>run_before(1)
</td>
<td>ZerosLeft=2; run_before=1
</td>
<td>01
</td></tr>
<tr>
<td>run_before(0)
</td>
<td>ZerosLeft=1; run_before=1
</td>
<td>No code required; last coefficient.
</td></tr></tbody></table>
<table class="wikitable floatright">
<tbody><tr>
<th>Code
</th>
<th>Element
</th>
<th>Value
</th>
<th>Output array
</th></tr>
<tr>
<td>0000100
</td>
<td>coeff_token
</td>
<td>Total Coeffs=5, T1s=3
</td>
<td>Empty
</td></tr>
<tr>
<td>0
</td>
<td>T1 sign
</td>
<td>+
</td>
<td><u>1</u>
</td></tr>
<tr>
<td>1
</td>
<td>T1 sign
</td>
<td>-
</td>
<td><u>−1</u>, 1
</td></tr>
<tr>
<td>1
</td>
<td>T1 sign
</td>
<td>-
</td>
<td><u>−1</u>, −1, 1
</td></tr>
<tr>
<td>1
</td>
<td>Level
</td>
<td>+1
</td>
<td><u>1</u>, −1, −1, 1
</td></tr>
<tr>
<td>0010
</td>
<td>Level
</td>
<td>+3
</td>
<td><u>3</u>, 1, −1, −1, 1
</td></tr>
<tr>
<td>111
</td>
<td>TotalZeros
</td>
<td>3
</td>
<td>3, 1, −1, −1, 1
</td></tr>
<tr>
<td>10
</td>
<td>run_before
</td>
<td>1
</td>
<td>3, 1, −1, −1, <u>0</u>, 1
</td></tr>
<tr>
<td>1
</td>
<td>run_before
</td>
<td>0
</td>
<td>3, 1, −1, −1, 0, 1
</td></tr>
<tr>
<td>1
</td>
<td>run_before
</td>
<td>0
</td>
<td>3, 1, −1, −1, 0, 1
</td></tr>
<tr>
<td>01
</td>
<td>run_before
</td>
<td>1
</td>
<td>3, <u>0</u>, 1, −1, −1, 0, 1
</td></tr></tbody></table>
<p>In all following examples, we assume that table Num-VLC0 is used to encode coeff_token.
</p>

<p>0, 3, 0, 1, −1, −1, 0, 1, 0…
TotalCoeffs = 5 (indexed from highest frequency [4] to lowest frequency [0])
</p><p>TotalZeros = 3
</p><p>T1s = 3 (in fact there are 4 trailing ones but only 3 can be encoded as a "special case")
</p><p>Encoding:
</p><p>The transmitted bitstream for this block is 000010001110010111101101.
</p><p>Decoding:
The output array is "built up" from the decoded values as shown below. Values added to the output array at each stage are underlined.
</p><p>The decoder has inserted two zeros; however, TotalZeros is equal to 3 and so another 1 zero is inserted before the lowest coefficient, making the final output array: 0, 3, 0, 1, −1, −1, 0, 1
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Advanced_Video_Coding#Features" title="Advanced Video Coding">H.264 (entropy coding)</a></li>
<li><a href="Data_compression" title="Data compression">Data compression</a></li>
<li><a href="Lossless_compression" title="Lossless compression">Lossless compression</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul><li><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFRichardson2011" class="citation web cs1">Richardson, Iain (August 28, 2011). <a rel="nofollow" class="external text" href="http://www.staroceans.org/e-book/vcodex/H264_cavlc_wp.pdf">"H.264 / AVC Context Adaptive Variable Length Coding"</a> <span class="cs1-format">(PDF)</span>. Vcodex<span class="reference-accessdate">. Retrieved <span class="nowrap">17 November</span> 2024</span>.</cite></li></ul>
<style data-mw-deduplicate="TemplateStyles:r1271159938">
/* start https://en.wikipedia.org/ */


.mw-parser-output .asbox{position:relative;overflow:hidden}.mw-parser-output .asbox table{background:transparent}.mw-parser-output .asbox p{margin:0}.mw-parser-output .asbox p+p{margin-top:0.25em}.mw-parser-output .asbox-body{font-style:italic}.mw-parser-output .asbox-note{font-size:smaller}.mw-parser-output .asbox .navbar{position:absolute;top:-0.75em;right:1em;display:none}.mw-parser-output :not(p):not(.asbox)+style+.asbox,.mw-parser-output :not(p):not(.asbox)+link+.asbox{margin-top:3em}


/* end https://en.wikipedia.org/ */
</style></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2024-11-17" href="https://en.wikipedia.org/wiki/?title=Context-adaptive_variable-length_coding&amp;oldid=1257993500">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>